package org.hackystat.ui.telemetryviewer.gwt.client;

import com.google.gwt.user.client.ui.Composite;

/**
 * Represents an Chart widget. Chart widget contains a simple handler {@link ChartHandler}. that
 * provides all information.
 *
 * @author Pavel Senin.
 *
 */
public class ChartWidget
    extends Composite {

  /**
   * Encapsulated information about a chart. Each chart is expected to have a static
   * <code>init()</code> method that will be called by the wrapper on startup.
   *
   * @author Pavel Senin.
   */
  public abstract static class ChartHandler {
    private ChartWidget instance;
    private String name, description;

    /**
     * Sets the chart information.
     *
     * @param name the chart name.
     * @param desc the chart description.
     */
    public ChartHandler(String name, String desc) {
      this.name = name;
      description = desc;
    }

    /**
     * Creates chart instance.
     *
     * @return chart instance.
     */
    public abstract ChartWidget createInstance();

    /**
     * Reports chart description.
     *
     * @return chart description.
     */
    public String getDescription() {
      return description;
    }

    /**
     * Reports chart instance, if instance not found creates one.
     *
     * @return chart instance.
     */
    public final ChartWidget getInstance() {
      if (instance != null) {
        return instance;
      }
      return (instance = createInstance());
    }

    /**
     * Reports this chart name.
     *
     * @return chart name.
     */
    public String getName() {
      return name;
    }
  }

  /**
   * Sets the telemetry time span.
   *
   * @param span the amount of days from current date to show the telemetry chart.
   */
  public void setSpan(String span) {
    assert true;
  }

}
